class SelectFilesController < ApplicationController
  def index
    @select_files = SelectFile.all
  end

  def show
    @select_file = SelectFile.find(params[:id])
  end

  def new
    @select_file = SelectFile.new
  end

  def create
    @select_file = SelectFile.new(params[:select_file])
    if @select_file.save
      @select_file.loadXML()
      redirect_to @select_file, :notice => "Successfully created select file."
    else
      render :action => 'new'
    end
  end

  def edit
    @select_file = SelectFile.find(params[:id])
  end

  def update
    @select_file = SelectFile.find(params[:id])
    if @select_file.update_attributes(params[:select_file])
      redirect_to @select_file, :notice  => "Successfully updated select file."
    else
      render :action => 'edit'
    end
  end

  def destroy
    @select_file = SelectFile.find(params[:id])
    @select_file.destroy
    redirect_to select_files_url, :notice => "Successfully destroyed select file."
  end
  
  def search
  end
  
  def searching
    title = params[:search_items][:title]
    @founded = Title.all.select{|j| j.text=~/(.*)#{title}(.*)/}
  end
  
  def loadXML
    SelectFile.loadXML(params[:load])
    redirect_to main_path
  end
end
